<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>

</body>
<script type="text/javascript">
    /**
     * @Description:
     * @author 朱志文
     * @date 2021/9/24
     */
    var arr = [10, 2, 5, 27, 98, 31];
    console.log('待排序数组：' + arr);
    for (let i = 0; i < arr.length; ++i) {
        for (let j = 0; j < arr.length - i; ++j) {
            if (arr[j] > arr[j + 1]) {
                [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
            }
        }
    }
    console.log('排序后的数组:' + arr)
</script>
</html>